class Parser
    def initialize(string)
        Logger.debug("Handling string: #{string}")
        @tokens = string.split(/ /)
        @pos = 0
    end
    
    def nextToken()
            @token = @tokens[@pos] 
            @pos += 1
            if (@token =~ /[0-9]/) != nil
                return TokenType::INTEGER
            end
            case @token
                when "+" then return TokenType::PLUS_OP
                when "-" then return TokenType::MINUS_OP
                when "*" then return TokenType::MULT_OP
            end
            return nextToken()
    end
    
    def createTree()
        tokenType = nextToken
        Logger.debug("#{@token} of type (#{tokenType})")
        if(tokenType == TokenType::INTEGER)
            # <expr> ::= integer
            return Tree.new(nil,  @token,  tokenType,  nil,  nil,  true)
        else
            #<expr> ::= + <expr> <expr>
            return Tree.new(nil,  @token,  tokenType,  createTree,  createTree,  false)
        end
    end
end
